using System;
using System.Collections;

namespace LocalBoard.Domain
{
	/// <summary>
	/// Summary description for Profile.
	/// </summary>
	public class Profile
	{
		private int _id;
		private string _userId;
		private string _userName;
		private string _password;
		private string _email;
		private ArrayList _userRoles;
		private string _photoPath;
		private string _customInfo;

		public int Id
		{
			get{return _id;}
		}
		public string UserId
		{
			get{return _userId;}
			set{_userId = value;}
		}
		public string UserName
		{
			get{return _userName;}
			set{_userName = value;}
		}
		public string Password
		{
			get{return _password;}
			set{_password = value;}
		}
		public string Email
		{
			get{return _email;}
			set{_email = value;}
		}
		/// <summary>
		/// <see cref="UserRole">UserRole</see> type array list
		/// </summary>
		public ArrayList UserRoles
		{
			get{return _userRoles;}
		}
		public string PhotoPath
		{
			get {return _photoPath;}
			set{_photoPath = value;}
		}
		public string CustomInfo
		{
			get {return _customInfo;}
			set {_customInfo = value;}
		}

		#region Static creation methods
		public static Profile LoadProfileFromPersistentStore(int id, string userId, string userName, string password, string email, string photoPath, string customInfo, ArrayList userRoles)
		{
			return new Profile(id, userId, userName, password, email, photoPath, customInfo, userRoles);
		}
		public static Profile CreateProfile(string userId, string userName, string password, string email, string photoPath, string customInfo)
		{
			return new Profile(userId, userName, password, email, photoPath, customInfo);
		}
		#endregion

		/// <summary>
		/// For loading from persistent store
		/// </summary>
		/// <param name="id"></param>
		/// <param name="userId"></param>
		/// <param name="userName"></param>
		/// <param name="password"></param>
		/// <param name="email"></param>
		/// <param name="userRoles"></param>
		[Obsolete("This will be deleted soon. Please use static creation method, LoadProfileFromPersistentStore instead.")]
		public Profile(int id, string userId, string userName, string password, string email, ArrayList userRoles) : this(id, userId, userName, password, email, "", "", userRoles)
		{}
		/// <summary>
		/// For loading from persistent store
		/// </summary>
		/// <param name="id"></param>
		/// <param name="userId"></param>
		/// <param name="userName"></param>
		/// <param name="password"></param>
		/// <param name="email"></param>
		/// <param name="photoPath"></param>
		/// <param name="customInfo"></param>
		/// <param name="userRoles"></param>
		[Obsolete("This will be hidden soon. Please use static creation method, LoadProfileFromPersistentStore instead.")]
		public Profile(int id, string userId, string userName, string password, string email, string photoPath, string customInfo, ArrayList userRoles) : this(userId, userName, password, email, photoPath, customInfo)
		{
			_id = id;
			_userRoles = userRoles;
		}
		[Obsolete("This will be deleted soon. Please use static creation method, CreateProfile instead.")]
		public Profile(string userId, string userName, string password, string email) : this(userId, userName, password, email, "", "")
		{}
		[Obsolete("This will be hidden soon. Please use static creation method, CreateProfile instead.")]
		public Profile(string userId, string userName, string password, string email, string photoPath, string customInfo)
		{
			_userId = userId;
			_userName = userName;
			_password = password;
			_email = email;
			_photoPath = photoPath;
			_customInfo = customInfo;
		}
		[Obsolete("This will be deleted soon. Please use other static creation method instead.")]
		public Profile(int id)
		{
			_id = id;
		}

		public bool IsInRole(string role)
		{
			foreach(UserRole userRole in _userRoles)
			{
				if(userRole.Name.ToUpper() == role.ToUpper())
					return true;
			}
			return false;
		}

		public bool IsInRole(int roleId)
		{
			foreach(UserRole userRole in _userRoles)
			{
				if(userRole.Id == roleId)
					return true;
			}
			return false;
		}

		public override bool Equals(object obj)
		{
			if(obj is Profile)
				return this._id == ((Profile)obj).Id;
			else
				return base.Equals(obj);
		}

		public override string ToString()
		{
			return _userName + "(" + _userId + ")";
		}

	}
}
